Conversation
Walkthrough이 변경사항은 NodeGroup, Node, Section 서비스 구현에서 생성, 수정, 소프트 삭제 시 수행되던 정렬(reorder) 및 순서 조정 로직을 모두 제거하였습니다. 각 서비스의 CRUD 메서드는 이제 단순히 엔티티를 저장, 수정, 삭제만 수행하며, 정렬 관련 메서드와 관련 import도 삭제되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant ServiceImpl
Client->>ServiceImpl: create/update/deleteSoft 요청
ServiceImpl-->>ServiceImpl: 엔티티 저장/수정/삭제 (정렬 로직 없음)
ServiceImpl-->>Client: 결과 반환
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 5
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java(2 hunks)src/main/java/com/handongapp/cms/service/impl/NodeServiceImpl.java(2 hunks)src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java (1)
src/main/java/com/handongapp/cms/dto/v1/NodeGroupDto.java (1)
NodeGroupDto(15-146)
src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java (1)
src/main/java/com/handongapp/cms/dto/v1/SectionDto.java (1)
SectionDto(12-116)
src/main/java/com/handongapp/cms/service/impl/NodeServiceImpl.java (1)
src/main/java/com/handongapp/cms/dto/v1/NodeDto.java (1)
NodeDto(10-121)
🔇 Additional comments (4)
src/main/java/com/handongapp/cms/service/impl/NodeServiceImpl.java (2)
44-49: 변경사항이 적절합니다.노드 생성 로직이 단순화되었으며, 불필요한 재정렬 로직이 제거되었습니다.
70-78:⚠️ Potential issue엔티티 변경사항이 저장되지 않습니다.
req.applyTo(entity)로 엔티티를 수정한 후 저장하지 않고 있습니다.@Transactional이 있어 dirty checking으로 자동 저장될 수 있지만, 명시적으로 저장하는 것이 안전합니다.다음과 같이 수정하세요:
public NodeDto.Response update(String nodeId, NodeDto.UpdateRequest req) { TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N") .orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId)); if (req.getData() != null) { // NodeDataValidator.validate(entity.getType(), req.getData()); } req.applyTo(entity); + nodeRepository.save(entity); return NodeDto.Response.from(entity); }Likely an incorrect or invalid review comment.
src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java (1)
49-53: 변경사항이 적절합니다.노드 그룹 생성 로직이 단순화되었으며, 불필요한 재정렬 로직이 제거되었습니다.
src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java (1)
23-27: 변경사항이 적절합니다.섹션 생성 로직이 단순화되었으며, 불필요한 재정렬 로직이 제거되었습니다.
| public void deleteSoft(String nodeId) { | ||
| TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N") | ||
| .orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId)); | ||
|
|
||
| String nodeGroupId = entity.getNodeGroupId(); | ||
| entity.setDeleted("Y"); | ||
| entity.setOrder(null); // Mark order as irrelevant for soft-deleted items | ||
| nodeRepository.save(entity); // Persist the soft deletion | ||
|
|
||
| // Reorder remaining active nodes | ||
| reorderAndPersistNodes(nodeGroupId, null, null); | ||
| } | ||
|
|
||
| private TbNode reorderAndPersistNodes(String nodeGroupId, @Nullable TbNode targetNode, @Nullable Integer requestedOrderForTarget) { | ||
| List<TbNode> currentNodesInDb = nodeRepository.findByNodeGroupIdAndDeletedOrderByOrderAsc(nodeGroupId, "N"); | ||
|
|
||
| List<TbNode> nodesToProcess = new ArrayList<>(); | ||
| boolean isTargetNew = (targetNode != null && targetNode.getId() == null); | ||
|
|
||
| for (TbNode n : currentNodesInDb) { | ||
| if (targetNode != null && n.getId() != null && n.getId().equals(targetNode.getId()) && !isTargetNew) { | ||
| continue; | ||
| } | ||
| nodesToProcess.add(n); | ||
| } | ||
|
|
||
| TbNode nodeToReturn = targetNode; | ||
|
|
||
| if (targetNode != null) { | ||
| int insertionIndex; | ||
| Integer effectiveOrder = requestedOrderForTarget; | ||
|
|
||
| if (effectiveOrder == null) { | ||
| if (!isTargetNew) { | ||
| effectiveOrder = targetNode.getOrder(); | ||
| } | ||
| } | ||
|
|
||
| if (effectiveOrder == null) { | ||
| insertionIndex = nodesToProcess.size(); | ||
| } else { | ||
| insertionIndex = Math.max(0, Math.min(effectiveOrder, nodesToProcess.size())); | ||
| } | ||
| nodesToProcess.add(insertionIndex, targetNode); | ||
| } | ||
|
|
||
| for (int i = 0; i < nodesToProcess.size(); i++) { | ||
| TbNode node = nodesToProcess.get(i); | ||
| node.setOrder(i); | ||
| } | ||
|
|
||
| if (!nodesToProcess.isEmpty()) { | ||
| nodeRepository.saveAll(nodesToProcess); | ||
| } | ||
|
|
||
| return nodeToReturn; | ||
| } |
There was a problem hiding this comment.
소프트 삭제가 저장되지 않습니다.
엔티티의 deleted 플래그를 설정한 후 저장하지 않고 있습니다.
다음과 같이 수정하세요:
public void deleteSoft(String nodeId) {
TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N")
.orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId));
entity.setDeleted("Y");
+ nodeRepository.save(entity);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public void deleteSoft(String nodeId) { | |
| TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N") | |
| .orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId)); | |
| String nodeGroupId = entity.getNodeGroupId(); | |
| entity.setDeleted("Y"); | |
| entity.setOrder(null); // Mark order as irrelevant for soft-deleted items | |
| nodeRepository.save(entity); // Persist the soft deletion | |
| // Reorder remaining active nodes | |
| reorderAndPersistNodes(nodeGroupId, null, null); | |
| } | |
| private TbNode reorderAndPersistNodes(String nodeGroupId, @Nullable TbNode targetNode, @Nullable Integer requestedOrderForTarget) { | |
| List<TbNode> currentNodesInDb = nodeRepository.findByNodeGroupIdAndDeletedOrderByOrderAsc(nodeGroupId, "N"); | |
| List<TbNode> nodesToProcess = new ArrayList<>(); | |
| boolean isTargetNew = (targetNode != null && targetNode.getId() == null); | |
| for (TbNode n : currentNodesInDb) { | |
| if (targetNode != null && n.getId() != null && n.getId().equals(targetNode.getId()) && !isTargetNew) { | |
| continue; | |
| } | |
| nodesToProcess.add(n); | |
| } | |
| TbNode nodeToReturn = targetNode; | |
| if (targetNode != null) { | |
| int insertionIndex; | |
| Integer effectiveOrder = requestedOrderForTarget; | |
| if (effectiveOrder == null) { | |
| if (!isTargetNew) { | |
| effectiveOrder = targetNode.getOrder(); | |
| } | |
| } | |
| if (effectiveOrder == null) { | |
| insertionIndex = nodesToProcess.size(); | |
| } else { | |
| insertionIndex = Math.max(0, Math.min(effectiveOrder, nodesToProcess.size())); | |
| } | |
| nodesToProcess.add(insertionIndex, targetNode); | |
| } | |
| for (int i = 0; i < nodesToProcess.size(); i++) { | |
| TbNode node = nodesToProcess.get(i); | |
| node.setOrder(i); | |
| } | |
| if (!nodesToProcess.isEmpty()) { | |
| nodeRepository.saveAll(nodesToProcess); | |
| } | |
| return nodeToReturn; | |
| } | |
| public void deleteSoft(String nodeId) { | |
| TbNode entity = nodeRepository.findByIdAndDeleted(nodeId, "N") | |
| .orElseThrow(() -> new EntityNotFoundException("Node not found with id: " + nodeId)); | |
| entity.setDeleted("Y"); | |
| nodeRepository.save(entity); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/NodeServiceImpl.java around
lines 82 to 86, the soft delete method sets the deleted flag on the entity but
does not persist this change. To fix this, after setting the deleted flag to
"Y", call the save method on nodeRepository to save the updated entity.
| public void deleteSoft(String id) { | ||
| TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N") | ||
| .orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id)); | ||
|
|
||
| String sectionId = entity.getSectionId(); | ||
| entity.setDeleted("Y"); | ||
| entity.setOrder(null); // Mark order as irrelevant for soft-deleted items | ||
| nodeGroupRepository.save(entity); // Persist the soft deletion | ||
|
|
||
| // Reorder remaining active node groups | ||
| reorderAndPersistNodeGroups(sectionId, null, null); | ||
| } | ||
|
|
||
| private TbNodeGroup reorderAndPersistNodeGroups(String sectionId, @Nullable TbNodeGroup targetNodeGroup, @Nullable Integer requestedOrderForTarget) { | ||
| List<TbNodeGroup> currentNodeGroupsInDb = nodeGroupRepository.findBySectionIdAndDeletedOrderByOrderAsc(sectionId, "N"); | ||
|
|
||
| List<TbNodeGroup> nodeGroupsToProcess = new ArrayList<>(); | ||
| boolean isTargetNew = (targetNodeGroup != null && targetNodeGroup.getId() == null); | ||
|
|
||
| for (TbNodeGroup ng : currentNodeGroupsInDb) { | ||
| if (targetNodeGroup != null && ng.getId() != null && ng.getId().equals(targetNodeGroup.getId()) && !isTargetNew) { | ||
| continue; | ||
| } | ||
| nodeGroupsToProcess.add(ng); | ||
| } | ||
|
|
||
| TbNodeGroup nodeGroupToReturn = targetNodeGroup; | ||
|
|
||
| if (targetNodeGroup != null) { | ||
| int insertionIndex; | ||
| Integer effectiveOrder = requestedOrderForTarget; | ||
|
|
||
| if (effectiveOrder == null) { | ||
| if (!isTargetNew) { | ||
| effectiveOrder = targetNodeGroup.getOrder(); | ||
| } | ||
| } | ||
|
|
||
| if (effectiveOrder == null) { | ||
| insertionIndex = nodeGroupsToProcess.size(); | ||
| } else { | ||
| insertionIndex = Math.max(0, Math.min(effectiveOrder, nodeGroupsToProcess.size())); | ||
| } | ||
| nodeGroupsToProcess.add(insertionIndex, targetNodeGroup); | ||
| } | ||
|
|
||
| for (int i = 0; i < nodeGroupsToProcess.size(); i++) { | ||
| TbNodeGroup nodeGroup = nodeGroupsToProcess.get(i); | ||
| nodeGroup.setOrder(i); | ||
| } | ||
|
|
||
| if (!nodeGroupsToProcess.isEmpty()) { | ||
| nodeGroupRepository.saveAll(nodeGroupsToProcess); | ||
| } | ||
|
|
||
| return nodeGroupToReturn; | ||
| } |
There was a problem hiding this comment.
소프트 삭제가 저장되지 않습니다.
엔티티의 deleted 플래그를 설정한 후 저장하지 않고 있습니다.
다음과 같이 수정하세요:
public void deleteSoft(String id) {
TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id));
entity.setDeleted("Y");
+ nodeGroupRepository.save(entity);
}🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java
around lines 83 to 87, the soft delete method sets the deleted flag on the
entity but does not save the updated entity back to the repository. Fix this by
calling the save method on nodeGroupRepository with the modified entity after
setting the deleted flag to "Y" to persist the change.
| public NodeGroupDto.Response update(String id, NodeGroupDto.UpdateRequest req) { | ||
| TbNodeGroup entityToUpdate = nodeGroupRepository.findByIdAndDeleted(id, "N") | ||
| TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N") | ||
| .orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id)); | ||
|
|
||
| String sectionId = entityToUpdate.getSectionId(); | ||
|
|
||
| // Apply changes from DTO. Assumes req.applyTo updates entityToUpdate.order if req.getOrder() is not null. | ||
| req.applyTo(entityToUpdate); | ||
|
|
||
| // entityToUpdate.getOrder() will be the requested new order if specified in DTO, or original order if not. | ||
| TbNodeGroup updatedEntity = reorderAndPersistNodeGroups(sectionId, entityToUpdate, entityToUpdate.getOrder()); | ||
| return NodeGroupDto.Response.from(updatedEntity); | ||
| req.applyTo(entity); | ||
| return NodeGroupDto.Response.from(entity); | ||
| } |
There was a problem hiding this comment.
엔티티 변경사항이 저장되지 않습니다.
req.applyTo(entity)로 엔티티를 수정한 후 저장하지 않고 있습니다.
다음과 같이 수정하세요:
public NodeGroupDto.Response update(String id, NodeGroupDto.UpdateRequest req) {
TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id));
req.applyTo(entity);
+ nodeGroupRepository.save(entity);
return NodeGroupDto.Response.from(entity);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public NodeGroupDto.Response update(String id, NodeGroupDto.UpdateRequest req) { | |
| TbNodeGroup entityToUpdate = nodeGroupRepository.findByIdAndDeleted(id, "N") | |
| TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N") | |
| .orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id)); | |
| String sectionId = entityToUpdate.getSectionId(); | |
| // Apply changes from DTO. Assumes req.applyTo updates entityToUpdate.order if req.getOrder() is not null. | |
| req.applyTo(entityToUpdate); | |
| // entityToUpdate.getOrder() will be the requested new order if specified in DTO, or original order if not. | |
| TbNodeGroup updatedEntity = reorderAndPersistNodeGroups(sectionId, entityToUpdate, entityToUpdate.getOrder()); | |
| return NodeGroupDto.Response.from(updatedEntity); | |
| req.applyTo(entity); | |
| return NodeGroupDto.Response.from(entity); | |
| } | |
| public NodeGroupDto.Response update(String id, NodeGroupDto.UpdateRequest req) { | |
| TbNodeGroup entity = nodeGroupRepository.findByIdAndDeleted(id, "N") | |
| .orElseThrow(() -> new EntityNotFoundException("NodeGroup not found with id: " + id)); | |
| req.applyTo(entity); | |
| nodeGroupRepository.save(entity); | |
| return NodeGroupDto.Response.from(entity); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/NodeGroupServiceImpl.java
around lines 74 to 79, after modifying the entity with req.applyTo(entity), the
changes are not saved to the database. Fix this by calling
nodeGroupRepository.save(entity) after applying the updates to persist the
changes before returning the response.
| public SectionDto.Response update(String id, SectionDto.UpdateRequest req) { | ||
| TbSection entityToUpdate = sectionRepository.findByIdAndDeleted(id, "N") | ||
| TbSection entity = sectionRepository.findByIdAndDeleted(id, "N") | ||
| .orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id)); | ||
|
|
||
| String courseId = entityToUpdate.getCourseId(); | ||
|
|
||
| // Apply changes from DTO. Assumes req.applyTo updates entityToUpdate.order if req.getOrder() is not null. | ||
| req.applyTo(entityToUpdate); | ||
|
|
||
| // entityToUpdate.getOrder() will be the requested new order if specified in DTO, or original order if not. | ||
| TbSection updatedEntity = reorderAndPersist(courseId, entityToUpdate, entityToUpdate.getOrder()); | ||
| return SectionDto.Response.from(updatedEntity); | ||
| req.applyTo(entity); | ||
| return SectionDto.Response.from(entity); | ||
| } |
There was a problem hiding this comment.
엔티티 변경사항이 저장되지 않습니다.
req.applyTo(entity)로 엔티티를 수정한 후 저장하지 않고 있습니다.
다음과 같이 수정하세요:
public SectionDto.Response update(String id, SectionDto.UpdateRequest req) {
TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));
req.applyTo(entity);
+ sectionRepository.save(entity);
return SectionDto.Response.from(entity);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public SectionDto.Response update(String id, SectionDto.UpdateRequest req) { | |
| TbSection entityToUpdate = sectionRepository.findByIdAndDeleted(id, "N") | |
| TbSection entity = sectionRepository.findByIdAndDeleted(id, "N") | |
| .orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id)); | |
| String courseId = entityToUpdate.getCourseId(); | |
| // Apply changes from DTO. Assumes req.applyTo updates entityToUpdate.order if req.getOrder() is not null. | |
| req.applyTo(entityToUpdate); | |
| // entityToUpdate.getOrder() will be the requested new order if specified in DTO, or original order if not. | |
| TbSection updatedEntity = reorderAndPersist(courseId, entityToUpdate, entityToUpdate.getOrder()); | |
| return SectionDto.Response.from(updatedEntity); | |
| req.applyTo(entity); | |
| return SectionDto.Response.from(entity); | |
| } | |
| public SectionDto.Response update(String id, SectionDto.UpdateRequest req) { | |
| TbSection entity = sectionRepository.findByIdAndDeleted(id, "N") | |
| .orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id)); | |
| req.applyTo(entity); | |
| sectionRepository.save(entity); | |
| return SectionDto.Response.from(entity); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java around
lines 48 to 53, after modifying the entity with req.applyTo(entity), the changes
are not saved to the database. Fix this by calling
sectionRepository.save(entity) after applying the updates to persist the changes
before returning the response.
| public void deleteSoft(String id) { | ||
| TbSection entity = sectionRepository.findByIdAndDeleted(id, "N") | ||
| .orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id)); | ||
|
|
||
| String courseId = entity.getCourseId(); | ||
| entity.setDeleted("Y"); | ||
| entity.setOrder(null); // Mark order as irrelevant for soft-deleted items | ||
| sectionRepository.save(entity); // Persist the soft deletion | ||
|
|
||
| // Reorder remaining active sections | ||
| reorderAndPersist(courseId, null, null); | ||
| } | ||
|
|
||
| private TbSection reorderAndPersist(String courseId, @Nullable TbSection targetSection, @Nullable Integer requestedOrderForTarget) { | ||
| List<TbSection> currentSectionsInDb = sectionRepository.findByCourseIdAndDeletedOrderByOrderAsc(courseId, "N"); | ||
|
|
||
| List<TbSection> sectionsToProcess = new ArrayList<>(); | ||
| boolean isTargetNew = (targetSection != null && targetSection.getId() == null); | ||
|
|
||
| // Populate sectionsToProcess with existing sections, excluding the targetSection if it's being updated | ||
| for (TbSection s : currentSectionsInDb) { | ||
| if (targetSection != null && s.getId() != null && s.getId().equals(targetSection.getId()) && !isTargetNew) { | ||
| // Skip the old version of targetSection if it's an update of an existing entity | ||
| continue; | ||
| } | ||
| sectionsToProcess.add(s); | ||
| } | ||
|
|
||
| // If targetSection is provided (create or update), add it to the list at the correct position | ||
| // Keep a reference to return, as the instance in targetSection variable might be the one from DB | ||
| // or a new one. The one added to sectionsToProcess is what gets its ID populated if new. | ||
| TbSection sectionToReturn = targetSection; | ||
|
|
||
| if (targetSection != null) { | ||
| int insertionIndex; | ||
| Integer effectiveOrder = requestedOrderForTarget; | ||
|
|
||
| // If no order is specified in the request for an existing item, | ||
| // use its current order to maintain its relative position unless other items shift it. | ||
| if (effectiveOrder == null) { | ||
| if (!isTargetNew) { // Existing item, order not specified in update DTO | ||
| effectiveOrder = targetSection.getOrder(); // Use its current order for placement logic | ||
| } | ||
| // If still null (e.g., new item and DTO order was null), it will be appended. | ||
| } | ||
|
|
||
| if (effectiveOrder == null) { | ||
| insertionIndex = sectionsToProcess.size(); // Append to the end | ||
| } else { | ||
| // Ensure insertionIndex is within the bounds of [0, sectionsToProcess.size()] | ||
| insertionIndex = Math.max(0, Math.min(effectiveOrder, sectionsToProcess.size())); | ||
| } | ||
| sectionsToProcess.add(insertionIndex, targetSection); | ||
| } | ||
|
|
||
| // Re-assign sequential order values from 0 to the items in sectionsToProcess | ||
| for (int i = 0; i < sectionsToProcess.size(); i++) { | ||
| TbSection section = sectionsToProcess.get(i); | ||
| section.setOrder(i); | ||
| } | ||
|
|
||
| if (!sectionsToProcess.isEmpty()) { | ||
| sectionRepository.saveAll(sectionsToProcess); // Use sectionsToProcess directly | ||
| } | ||
|
|
||
| // If targetSection was new, its ID is populated by saveAll. | ||
| // The 'sectionToReturn' (which is the 'targetSection' object passed in or created) | ||
| // is the instance that was added to sectionsToProcess and subsequently saved. | ||
| // So it should have the ID if it was new. | ||
| return sectionToReturn; | ||
| } |
There was a problem hiding this comment.
소프트 삭제가 저장되지 않습니다.
엔티티의 deleted 플래그를 설정한 후 저장하지 않고 있습니다.
다음과 같이 수정하세요:
public void deleteSoft(String id) {
TbSection entity = sectionRepository.findByIdAndDeleted(id, "N")
.orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id));
entity.setDeleted("Y");
+ sectionRepository.save(entity);
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public void deleteSoft(String id) { | |
| TbSection entity = sectionRepository.findByIdAndDeleted(id, "N") | |
| .orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id)); | |
| String courseId = entity.getCourseId(); | |
| entity.setDeleted("Y"); | |
| entity.setOrder(null); // Mark order as irrelevant for soft-deleted items | |
| sectionRepository.save(entity); // Persist the soft deletion | |
| // Reorder remaining active sections | |
| reorderAndPersist(courseId, null, null); | |
| } | |
| private TbSection reorderAndPersist(String courseId, @Nullable TbSection targetSection, @Nullable Integer requestedOrderForTarget) { | |
| List<TbSection> currentSectionsInDb = sectionRepository.findByCourseIdAndDeletedOrderByOrderAsc(courseId, "N"); | |
| List<TbSection> sectionsToProcess = new ArrayList<>(); | |
| boolean isTargetNew = (targetSection != null && targetSection.getId() == null); | |
| // Populate sectionsToProcess with existing sections, excluding the targetSection if it's being updated | |
| for (TbSection s : currentSectionsInDb) { | |
| if (targetSection != null && s.getId() != null && s.getId().equals(targetSection.getId()) && !isTargetNew) { | |
| // Skip the old version of targetSection if it's an update of an existing entity | |
| continue; | |
| } | |
| sectionsToProcess.add(s); | |
| } | |
| // If targetSection is provided (create or update), add it to the list at the correct position | |
| // Keep a reference to return, as the instance in targetSection variable might be the one from DB | |
| // or a new one. The one added to sectionsToProcess is what gets its ID populated if new. | |
| TbSection sectionToReturn = targetSection; | |
| if (targetSection != null) { | |
| int insertionIndex; | |
| Integer effectiveOrder = requestedOrderForTarget; | |
| // If no order is specified in the request for an existing item, | |
| // use its current order to maintain its relative position unless other items shift it. | |
| if (effectiveOrder == null) { | |
| if (!isTargetNew) { // Existing item, order not specified in update DTO | |
| effectiveOrder = targetSection.getOrder(); // Use its current order for placement logic | |
| } | |
| // If still null (e.g., new item and DTO order was null), it will be appended. | |
| } | |
| if (effectiveOrder == null) { | |
| insertionIndex = sectionsToProcess.size(); // Append to the end | |
| } else { | |
| // Ensure insertionIndex is within the bounds of [0, sectionsToProcess.size()] | |
| insertionIndex = Math.max(0, Math.min(effectiveOrder, sectionsToProcess.size())); | |
| } | |
| sectionsToProcess.add(insertionIndex, targetSection); | |
| } | |
| // Re-assign sequential order values from 0 to the items in sectionsToProcess | |
| for (int i = 0; i < sectionsToProcess.size(); i++) { | |
| TbSection section = sectionsToProcess.get(i); | |
| section.setOrder(i); | |
| } | |
| if (!sectionsToProcess.isEmpty()) { | |
| sectionRepository.saveAll(sectionsToProcess); // Use sectionsToProcess directly | |
| } | |
| // If targetSection was new, its ID is populated by saveAll. | |
| // The 'sectionToReturn' (which is the 'targetSection' object passed in or created) | |
| // is the instance that was added to sectionsToProcess and subsequently saved. | |
| // So it should have the ID if it was new. | |
| return sectionToReturn; | |
| } | |
| public void deleteSoft(String id) { | |
| TbSection entity = sectionRepository.findByIdAndDeleted(id, "N") | |
| .orElseThrow(() -> new EntityNotFoundException("Section not found with id: " + id)); | |
| entity.setDeleted("Y"); | |
| sectionRepository.save(entity); | |
| } |
🤖 Prompt for AI Agents
In src/main/java/com/handongapp/cms/service/impl/SectionServiceImpl.java around
lines 57 to 61, the method sets the deleted flag on the entity but does not save
the updated entity to the repository. To fix this, after setting
entity.setDeleted("Y"), call sectionRepository.save(entity) to persist the
change.
Reverts #188
Summary by CodeRabbit